
const countOptions = {
    namespaced: true,
    actions:{
        jia(context,value){
            console.log('actions中的jia被调用了')
            context.commit('JIA',value)
        },
        jian(context,value){
            console.log('actions中的jian被调用了')
            context.commit('JIAN',value)
        },
        jiaOdd(context,value){
            console.log('actions中的jiaOdd被调用了')
            context.commit('incrementOdd',value)
        },
        jiaWait(context,value){
            console.log('actions中的jiaWait被调用了')
            context.commit('incrementWait',value)
        },
    },
    mutations:{
        JIA(state,value){
            console.log('mutations中的JIA被调用了')
            state.sum += value
        },
        JIAN(state,value){
            console.log('mutations中的JIA被调用了')
            state.sum -= value
        },
        increment(state,value){
            console.log('mutations中的increment被调用了')
            state.sum += value
        },
        decrement(state,value){
            console.log('mutations中的decrement被调用了')
            state.sum -= value
        },
        incrementOdd(state,value){
            if(state.sum%2==1) {
                console.log('mutations中的incrementOdd被调用了')
                state.sum += value
            }
        },
        incrementWait(state,value){
            setTimeout(()=>{
                state.sum += value
            }, 500)
        }
    },
    state:{
        sum:0, //当前的和
        school: '尚硅谷',
        subject: '前端',
    },
    getters:{
        bigSum(state){
            return state.sum*10;
        }
    }
}

export default countOptions;
